function initTable(table) {
    table.render({
        elem : '#cartTable'
        ,url : serverBase+"shop"+"?userid="+sessionStorage.getItem("userid")
        ,page : false
        ,totalRow:true
        ,toolbar : '#toolbar'
           , response: {
                statusName: 'errorCode' //规定数据状态的字段名称，默认：code
                ,statusCode: 200 //规定成功的状态码，默认：0
                ,msgName: 'msg' //规定状态信息的字段名称，默认：msg
                ,dataName: 'data' //规定数据列表的字段名称，默认：data
            }
        , cols: [[
            {field: 'id', title: 'ID', hide: true,},
            // {type:'checkbox',},
            {field: 'gameid', title: "游戏号",hide: true},
            {field: 'userid', title: "用户号",hide: true},
            {field: 'gamename', title: "游戏名字",totalRowText:'总价格',},
            {field: 'price', title: "游戏价格",totalRow:true},
            {field: 'photo', title: "游戏图片", templet: '#picture'},
            {fixed: 'right', width:150, align:'center', toolbar: '#delByid'}
        ]],
    })
        table.on('toolbar(cartTable)' , function(obj) {
            var data = obj.data; //获得当前行数据
            var layEvent = obj.event; //获得 lay-event 对应的值
            // var checkStatus = table.checkStatus('idTest')
            switch (layEvent) {
                case 'clear' :
                    clearcartandler(layer,  obj);
                    break;
            }
        })
    table.on('tool(cartTable)' , function(obj) {
        var data = obj.data; //获得当前行数据
        var layEvent = obj.event; //获得 lay-event 对应的值
        // var checkStatus = table.checkStatus('idTest')
        switch (layEvent) {
            case 'delete' :
                deletecartandler(layer, data , obj ,table );
                break;
        }
    })
}
function clearcartandler(layer ){
    layer.open({
        content: '是否结算购物车？'
        ,btn: ['确定', '取消']
        ,yes: function(index, layero,data){
            layer.close(index) ;
            $.ajax({
                url:serverBase +"shop/clear"+"?userid="+sessionStorage.getItem('userid') ,
                type:'DELETE',
                // data:'userid='+sessionStorage.getItem('userid'),
                success:function(reqData) {
                    layer.msg(reqData.msg);
                    if (reqData.errorCode = 200) {
                        if(layer.msg("结算购物车成功")){
                            window.location.reload();
                        }

                    }
                }
            })
        }
        ,btn2: function(index, layero){
            window.location.reload();

        }
        ,cancel: function(){
            window.location.reload();
        }
    });
}
function deletecartandler(layer, data , obj ,table ){
        layer.confirm('是否删除 : ' + data.gamename + '?' , function(index){
                layer.close(index) ;
                $.ajax({
                    url : serverBase + "shop/delete/"+data.id,
                    type : 'DELETE',
                    success : function(reqData){
                        layer.msg(reqData.msg) ;
                        if(reqData.errorCode == 200) {
                            obj.del();
                        }
                    }
                })
            }
        )

}
